﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Identities;
using Domain.MainModule.IdentityTypes;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class IdentityTypeRepositoryTest : RepositoryTestsBase<IdentityType>
    {
       string identityTypeName = "Identity Type Name";
       
       public override System.Linq.Expressions.Expression<Func<IdentityType, bool>> FilterExpression
        {
            get { return a => a.Name == identityTypeName; }
        }

        public override System.Linq.Expressions.Expression<Func<IdentityType, Guid>> OrderByExpression
        {
            get { return a => a.TypeId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindIdentityType_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IIdentityTypeRepository repository = new IdentityTypeRepository(context,traceManager);

            //Act
            repository.GetBySpec(null);
        }
			
		[TestMethod()]
        public void FindIdentityType_Invoke_InvalidIdentityTypeNameReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IIdentityTypeRepository repository = new IdentityTypeRepository(context, traceManager);

			string invalidIdentityTypeName = "invalid identity type name";
            IdentityTypeNameSpecification spec = new IdentityTypeNameSpecification(invalidIdentityTypeName);

            //Act
            IEnumerable<IdentityType> identityTypes = repository.GetBySpec(spec);

            //Assert
            Assert.IsNotNull(identityTypes);
            Assert.IsTrue(identityTypes.Count() == 0);
        }
		
        [TestMethod()]
        public void FindIdentityTypeByIdentityTypeName_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            IIdentityTypeRepository repository = new IdentityTypeRepository(context, traceManager);

            IdentityTypeNameSpecification spec = new IdentityTypeNameSpecification(identityTypeName);

            //Act
            IEnumerable<IdentityType> identityTypes = repository.GetBySpec(spec);

            //Assert
            Assert.IsNotNull(identityTypes);
            Assert.IsTrue(identityTypes.Count() > 0);
        }
    }
}
